// pages/ukCollege2/ukCollege2.js
const app = getApp();
var host = app.globalData.host;
var self = null;

Page({
  data: {
    themeColor: '',
    defaultColor: '',
    borderColor: '',
    list: [],
    cnSchoolId: '',
    ukSchoolId: '',
    major: '',
    majorCount: ''
  },
  onLoad: function (options) {
    self = this;
    self.getStyle();
    self.setData({
      cnSchoolId: options.cnSchoolId,
      major: options.major
    })
    if (options.ukSchoolId) {
      self.setData({
        ukSchoolId: options.ukSchoolId
      })
    }
    wx.request({
      url: host + '/lx/search/submit2',
      data: {
        cnSchoolId: self.data.cnSchoolId,
        major: self.data.major,
        ukSchoolId: self.data.ukSchoolId
      },
      success: function(res) {
        // if (res.data.info.count || res.data.info.count === 0) {
        //   self.setData({
        //     majorCount: res.data.info.count
        //   })
        // }
        // var list = res.data.info.list;
        // for (var i = 0; i < list.length; i ++) {
        //   var item = list[i];
        //   // if (item.rank < item.schoolMaxRank || item.rank > item.schoolMinRank || item.rank > item.majorMinRank) {
        //   if (item.rank < item.minRank || item.rank > item.maxRank) {
        //     item.adviceType = 0; // 不建议申请
        //   // } else if ((item.rank >= item.schoolMaxRank && item.rank <= item.schoolMinRank) && ((item.majorCount == 0) || (item.majorCount != 0 && (item.rank < item.majorMinRank)))) {
        //   } else if (item.rank >= item.minRank && item.rank <= item.maxRank) {
        //     item.adviceType = 1; // 完全符合
        //   } else {
        //     item.adviceType = 2;
        //   }
        // }

        // self.setData({
        //   list: list
        // })
        self.setData({
          list: res.data.info
        })
      }
    })
  },
  getStyle() {
    self.setData({
      themeColor: app.globalData.themeColor,
      defaultColor: app.globalData.defaultColor,
      borderColor: app.globalData.borderColor
    })
  },
  selectSchool(e) {
    // 不建议申请 或 代表全部专业
    var mode = Number(e.currentTarget.dataset.mode);
    if (mode < 3) {
      return;
    }
    wx.navigateTo({
      url: "/pages/result/result?cnSchoolId=" + self.data.cnSchoolId + "&ukSchoolId=" + e.currentTarget.dataset.schoolid + "&major=" + self.data.major
    })
  }
})